diff --git a/setup.py b/setup.py
index 8505d2679..b565e97bd 100644
--- a/setup.py
+++ b/setup.py
@@ -21,7 +21,7 @@ install_requires = [
     'sphinxcontrib-htmlhelp',
     'sphinxcontrib-serializinghtml',
     'sphinxcontrib-qthelp',
-    'Jinja2>=2.3',
+    'Jinja2<3.1',
     'Pygments>=2.0',
     'docutils>=0.12',
     'snowballstemmer>=1.1',
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index b77202951..0aee5694d 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -1325,11 +1325,21 @@ class LaTeXTranslator(SphinxTranslator):
             self.body.append('\n\\begin{figure}[%s]\n\\centering\n' % align)
             if any(isinstance(child, nodes.caption) for child in node):
                 self.body.append('\\capstart\n')
+            else:
+                # Generate a unique identifier for the figure
+                unique_identifier = self.generate_unique_identifier(node)
+                self.body.append('\\label{fig:%s}\n' % unique_identifier)
             self.context.append('\\end{figure}\n')
 
     def depart_figure(self, node: Element) -> None:
         self.body.append(self.context.pop())
 
+    def generate_unique_identifier(self, node: Element) -> str:
+        # Use the index of the node in its parent and a hash of its attributes to generate a unique identifier
+        index = node.parent.index(node)
+        attributes_hash = hash(frozenset(node.attributes.items()))
+        return f'fig-{index}-{attributes_hash}'
+
     def visit_caption(self, node: Element) -> None:
         self.in_caption += 1
         if isinstance(node.parent, captioned_literal_block):
diff --git a/tox.ini b/tox.ini
index a61299979..e2baccc07 100644
--- a/tox.ini
+++ b/tox.ini
@@ -28,7 +28,7 @@ setenv =
     PYTHONWARNINGS = all,ignore::ImportWarning:importlib._bootstrap_external,ignore::DeprecationWarning:site,ignore::DeprecationWarning:distutils
     PYTEST_ADDOPTS = --color yes
 commands=
-    pytest --durations 25 {posargs}
+    pytest -rA --durations 25 {posargs}
 
 [testenv:flake8]
 basepython = python3
